﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using AbstraX.Contracts;
using SolutionFramework.BuildServiceReference;
using AbstraX.BuildWizard;
using BuildInvokeOperation = AbstraX.BuildWizard.BuildInvokeOperation;

namespace SolutionFramework.Services
{
    public class BuildProxy : IBuildProxy
    {
        private BuildServiceClient buildService = new BuildServiceClient();

        public void BuildMiddleLayer(string id)
        {
            buildService.BuildMiddleLayerAsync(id);
        }

        public BuildOperation<string> GetProperty(string UIComponentURL, string propertyName)
        {
            BuildOperation<string> operation = new BuildOperation<string>();

            buildService.GetPropertyAsync(UIComponentURL, propertyName);

            buildService.GetPropertyCompleted += (sender, e) =>
            {
                operation.SetCompleted(e.Result);
            };

            return operation;
        }

        public BuildInvokeOperation SetProperty(string UIComponentURL, string propertyName, string value)
        {
            BuildInvokeOperation operation = new BuildInvokeOperation();

            buildService.SetPropertyAsync(UIComponentURL, propertyName, value);

            buildService.SetPropertyCompleted += (sender, e) =>
            {
                operation.SetCompleted();
            };

            return operation;
        }

        public BuildOperation<bool> MoveNext(string lastUIComponentURL)
        {
            BuildOperation<bool> operation = new BuildOperation<bool>();

            buildService.MoveNextAsync(lastUIComponentURL);

            buildService.MoveNextCompleted += (sender, e) =>
            {
                operation.SetCompleted(e.Result);
            };

            return operation;
        }

        public void Finish(string lastUIComponentURL)
        {
            buildService.FinishAsync(lastUIComponentURL);
        }
    }
}
